package com.game.jumper.lghelp;

import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Random;

import org.loon.framework.android.game.core.geom.Shape;
import org.loon.framework.android.game.core.geom.Stroke;
import org.loon.framework.android.game.core.graphics.LColor;
import org.loon.framework.android.game.core.graphics.device.LGraphics;

import android.R.integer;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import com.game.jumper.bean.Board;
import com.game.jumper.game.Game;

public class Lg_Board implements ILgHelp
{

	private Game game;

	private LColor color;

	private Paint paint;

	public Lg_Board(Game game)
	{
		this.game = game;
		color = new LColor(222, 184, 135);
		paint = new Paint();

	}

	@Override
	public void draw(LGraphics g)
	{
		// TODO Auto-generated method stub
		List<Board> boards = game.getNextBoards();
		// c.drawText(Integer.toString(boards.size()), 50, 50, paint);
		if (boards != null)
		{
			for (Board bd : boards)
			{
				drawboard(g, bd);
			}
		}
	}

	// ����һ����
	void drawboard(LGraphics g, Board bd)
	{
		paint.setStrokeWidth((int) bd.getThick());
		g.setPaint(paint);
		List<Integer> xList = new ArrayList<Integer>();
		List<Integer> yList = new ArrayList<Integer>();
		if (bd.isRecover())
		{
			for (Entry<Double, Double> entry : bd.getLocations().entrySet())
			{
				xList.add(entry.getKey().intValue());
				yList.add(entry.getValue().intValue());
			}
			g.setColor(LColor.yellow);

			for (int i = 1; i < xList.size(); i++)
			{
				g.drawLine(xList.get(i - 1), yList.get(i - 1), xList.get(i), yList.get(i));
			}
		}
		else
		{
			if (bd.isActive())
			{
				g.setColor(LColor.yellow);
			}
			else
			{
				g.setColor(color);
			}
			if (bd.isLeft())
			{
				int left = 0;
				int hight = (int) bd.getHight();
				g.drawLine(left, hight, (int) bd.getWidth(), hight);

			}
			else
			{
				int w = g.getClipWidth();
				int left = w - (int) bd.getWidth();
				int hight = (int) bd.getHight();
				g.drawLine(left, hight, w, hight);
			}
		}
	}

}
